package org.qloudgen.borg.pages.frame;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.qloudgen.borg.CommonValues;
import org.qloudgen.borg.pages.common.BasePage;
import org.qloudgen.borg.security.LoginPage;

public class TopFrame extends BasePage{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private transient String userNo;
	
	public TopFrame(PageParameters pageParameters){
		
		super();
	
		userNo = CommonValues.getUserNo();
		
		// add form 
		Form<?> form = new Form<Object>("form");
		this.add(form);
	
		// add hello 
		form.add(new Label("hello",CommonValues.getHelloInfo(userNo)));
	
		// add refresh
		Link<?> refresh = new Link<Object>("refresh") {      
			private static final long serialVersionUID = 1L;
				public void onClick() {                 
					getRequestCycle().setResponsePage(getApplication().getHomePage());             
				}        
		};
		refresh.add(new AttributeModifier("target",new Model<String>("_parent")));
		form.add(refresh);
		
		// add logout
		Link<?> logout = new Link<Object>("logoutLink") {      
			private static final long serialVersionUID = 1L;
				public void onClick() {                 
					getSession().invalidate();  
	                getRequestCycle().setResponsePage(LoginPage.class);            
				}        
		};
		logout.add(new AttributeModifier("target",new Model<String>("_parent")));
		form.add(logout);
		
		addHeader();
	}
}
